
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>mybatis模块 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="cache.html" />
    
    
    <link rel="prev" href="spring.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    概要
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../architecture.html">
            
                <a href="../architecture.html">
            
                    
                    总体架构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../quick-start.html">
            
                <a href="../quick-start.html">
            
                    
                    快速开始
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../quickstart/confcenter.html">
            
                <a href="../quickstart/confcenter.html">
            
                    
                    配置中心
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../quickstart/oneplatform.html">
            
                <a href="../quickstart/oneplatform.html">
            
                    
                    oneplatform企业级开发平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../quickstart/passport.html">
            
                <a href="../quickstart/passport.html">
            
                    
                    统一认证平台
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../jeesuite-lib.html">
            
                <a href="../jeesuite-lib.html">
            
                    
                    jeesuite-libs使用文档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="common.html">
            
                <a href="common.html">
            
                    
                    common模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="common2.html">
            
                <a href="common2.html">
            
                    
                    common2模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="spring.html">
            
                <a href="spring.html">
            
                    
                    Spring模块
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.4" data-path="mybatis.html">
            
                <a href="mybatis.html">
            
                    
                    mybatis模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="cache.html">
            
                <a href="cache.html">
            
                    
                    cache模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="kafka.html">
            
                <a href="kafka.html">
            
                    
                    kafka模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="scheduler.html">
            
                <a href="scheduler.html">
            
                    
                    scheduler模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="filesystem.html">
            
                <a href="filesystem.html">
            
                    
                    filesystem模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="rest.html">
            
                <a href="rest.html">
            
                    
                    restAPI模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="springboot-starter.html">
            
                <a href="springboot-starter.html">
            
                    
                    springboot-starter模块
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../integration.html">
            
                <a href="../integration.html">
            
                    
                    系统集成
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../integration/confcenter.html">
            
                <a href="../integration/confcenter.html">
            
                    
                    集成配置中心
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../integration/passport.html">
            
                <a href="../integration/passport.html">
            
                    
                    集成认证中心
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../base-env-install.html">
            
                <a href="../base-env-install.html">
            
                    
                    附：基础环境搭建
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >mybatis模块</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x529F;&#x80FD;&#x8BF4;&#x660E;">&#x529F;&#x80FD;&#x8BF4;&#x660E;</h3>
<ul>
<li>&#x4EE3;&#x7801;&#x751F;&#x6210;&#x3001;&#x81EA;&#x52A8;CRUD&#x3001;&#x53EF;&#x65E0;&#x7F1D;&#x5BF9;&#x63A5;mybaits&#x589E;&#x5F3A;&#x6846;&#x67B6;<code>Mapper</code></li>
<li>&#x57FA;&#x4E8E;properties&#x914D;&#x7F6E;&#x591A;&#x6570;&#x636E;&#x6E90;&#x652F;&#x6301;&#xFF0C;&#x65E0;&#x9700;&#x4FEE;&#x6539;XML</li>
<li>&#x8BFB;&#x5199;&#x5206;&#x79BB;&#xFF0C;&#x4E8B;&#x52A1;&#x5185;&#x64CD;&#x4F5C;&#x5F3A;&#x5236;&#x8BFB;&#x4E3B;&#x5E93;</li>
<li>&#x57FA;&#x4E8E;&#x6CE8;&#x89E3;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x7BA1;&#x7406;&#xFF08;&#x6240;&#x6709;&#x67E5;&#x8BE2;&#x65B9;&#x6CD5;&#x7ED3;&#x679C;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x3001;&#x81EA;&#x52A8;&#x66F4;&#x65B0;&#xFF0C;&#x4E8B;&#x52A1;&#x56DE;&#x6EDA;&#x7F13;&#x5B58;&#x540C;&#x6B65;&#x56DE;&#x6EDA;&#x673A;&#x5236;&#xFF09;</li>
<li>&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x5B9E;&#x73B0;&#x57FA;&#x4E8E;<code>jeesuite-cache</code>&#x548C;<code>spring-data-redis</code></li>
<li>&#x5206;&#x9875;&#x7EC4;&#x4EF6;</li>
<li>&#x7B80;&#x5355;&#x5206;&#x5E93;&#x8DEF;&#x7531;&#xFF08;&#x4E0D;&#x652F;&#x6301;join&#x7B49;&#x8DE8;&#x5E93;&#x64CD;&#x4F5C;&#xFF09;</li>
</ul>
<h3 id="&#x4F7F;&#x7528;&#x8BF4;&#x660E;">&#x4F7F;&#x7528;&#x8BF4;&#x660E;</h3>
<h4 id="&#x6DFB;&#x52A0;&#x4F9D;&#x8D56;">&#x6DFB;&#x52A0;&#x4F9D;&#x8D56;</h4>
<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;com.jeesuite&lt;/groupId&gt;
    &lt;artifactId&gt;jeesuite-mybatis&lt;/artifactId&gt;
    &lt;version&gt;[&#x6700;&#x65B0;&#x7248;&#x672C;]&lt;/version&gt;
&lt;/dependency&gt;
</code></pre><h4 id="&#x4E00;&#x4E9B;&#x8BF4;&#x660E;">&#x4E00;&#x4E9B;&#x8BF4;&#x660E;</h4>
<h5 id="&#x4EE3;&#x7801;&#x751F;&#x6210;&#x53CA;&#x5176;&#x81EA;&#x52A8;crud">&#x4EE3;&#x7801;&#x751F;&#x6210;&#x53CA;&#x5176;&#x81EA;&#x52A8;crud</h5>
<p>&#x5DF2;&#x5B9E;&#x73B0;&#x65B9;&#x6CD5;</p>
<ul>
<li>getByKey</li>
<li>insert</li>
<li>insertSelective</li>
<li>updateByKey</li>
<li>updateByKeySelective</li>
<li>deleteByKey</li>
<li>selectAll</li>
</ul>
<h3 id="&#x7279;&#x522B;&#x8BF4;&#x660E;&#xFF1A;">&#x7279;&#x522B;&#x8BF4;&#x660E;&#xFF1A;</h3>
<ul>
<li>&#x5DF2;&#x7ECF;&#x65E0;&#x7F1D;&#x5BF9;&#x63A5;&#x4F18;&#x79C0;&#x7684;mybatis&#x589E;&#x5F3A;&#x6846;&#x67B6; <a href="http://git.oschina.net/free/Mapper" target="_blank">Mapper</a> &#xFF0C;&#x8BE5;&#x6846;&#x67B6;&#x529F;&#x80FD;&#x5F3A;&#x5927;&#xFF0C;&#x8BE5;&#x90E8;&#x5206;&#x63A8;&#x8350;&#x96C6;&#x6210;Mapper&#x6846;&#x67B6;&#x3002;</li>
</ul>
<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;tk.mybatis&lt;/groupId&gt;
    &lt;artifactId&gt;mapper&lt;/artifactId&gt;
    &lt;version&gt;[&lt;=3.4.3&#x6D4B;&#x8BD5;&#x8FC7;]&lt;/version&gt;
&lt;/dependency&gt;
</code></pre><hr>
<h5 id="&#x5176;&#x4ED6;&#x529F;&#x80FD;&#x8BF4;&#x660E;">&#x5176;&#x4ED6;&#x529F;&#x80FD;&#x8BF4;&#x660E;</h5>
<ul>
<li>&#x8BFB;&#x5199;&#x5206;&#x79BB;<ol>
<li>&#x6839;&#x636E;&#x6267;&#x884C;sql&#x7C7B;&#x578B;&#x81EA;&#x52A8;&#x8DEF;&#x7531;master/slave&#x5E93;</li>
<li>&#x652F;&#x6301;&#x57FA;&#x4E8E;properties&#x6587;&#x4EF6;&#x52A8;&#x6001;&#x6269;&#x5C55;slave&#x8282;&#x70B9;</li>
<li>&#x652F;&#x6301;@Transactional&#x5F3A;&#x5236;&#x4F7F;&#x7528;master&#x5E93;&#x67E5;&#x8BE2;</li>
</ol>
</li>
<li>&#x81EA;&#x52A8;&#x7F13;&#x5B58;<ol>
<li>&#x652F;&#x6301;&#x6240;&#x6709;mapper&#x81EA;&#x5B9A;&#x4E49;&#x67E5;&#x8BE2;&#x65B9;&#x6CD5;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x7BA1;&#x7406;&#xFF08;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x3001;&#x81EA;&#x52A8;&#x66F4;&#x65B0;&#xFF09;</li>
<li>&#x652F;&#x6301;&#x901A;&#x8FC7;@CacheEvictCascade&#x6CE8;&#x89E3;&#xFF0C;&#x7EA7;&#x8054;&#x7F13;&#x5B58;&#x66F4;&#x65B0;</li>
<li>&#x652F;&#x6301;&#x901A;&#x8FC7;EntityCacheHelper&#x624B;&#x52A8;&#x5199;&#x5165;/&#x66F4;&#x65B0;&#x7F13;&#x5B58;&#x5E76;&#x81EA;&#x52A8;&#x7EB3;&#x5165;&#x81EA;&#x52A8;&#x7BA1;&#x7406;&#x4F53;&#x7CFB;</li>
<li>&#x9632;&#x6B62;&#x7F13;&#x5B58;&#x7A7F;&#x900F;&#xFF0C;&#x53EF;&#x914D;&#x7F6E;&#x7F13;&#x5B58;null&#x503C;&#x5E76;&#x81EA;&#x52A8;&#x66F4;&#x65B0;</li>
</ol>
</li>
<li>&#x5206;&#x5E93;&#x8DEF;&#x7531;<ol>
<li>&#x53EA;&#x9002;&#x7528;&#x57FA;&#x672C;&#x7684;&#x5206;&#x5E93;&#x8DEF;&#x7531;&#xFF0C;&#x4E0D;&#x652F;&#x6301;&#x8DE8;&#x5E93;join&#x7B49;&#xFF0C;&#x672A;&#x7ECF;&#x8FC7;&#x4E25;&#x683C;&#x6D4B;&#x8BD5;&#x4E5F;&#x6CA1;&#x4E0A;&#x8FC7;&#x751F;&#x4EA7;&#x7CFB;&#x7EDF;&#xFF08;&#x53EA;&#x5F53;&#x4E2A;&#x7814;&#x7A76;&#x7528;&#xFF09;&#x3002;</li>
</ol>
</li>
<li>&#x5206;&#x9875;<ol>
<li>&#x652F;&#x6301;&#x901A;&#x8FC7;&#x6807;&#x6CE8;&#x6216;&#x8005;&#x5B9A;&#x4E49;page&#x65B9;&#x6CD5;&#x5B9E;&#x73B0;&#x7269;&#x7406;&#x5206;&#x9875;</li>
</ol>
</li>
</ul>
<h4 id="&#x914D;&#x7F6E;">&#x914D;&#x7F6E;</h4>
<pre><code>#mysql global config
db.group.size=1
db.shard.size=1000
db.driverClass=com.mysql.jdbc.Driver
db.initialSize=2
db.minIdle=1
db.maxActive=10
db.maxWait=60000
db.timeBetweenEvictionRunsMillis=60000
db.minEvictableIdleTimeMillis=300000
db.testOnBorrow=false
db.testOnReturn=false

#master
master.db.url=jdbc:mysql://localhost:3306/demo_db?seUnicode=true&amp;amp;characterEncoding=UTF-8
master.db.username=root
master.db.password=123456
master.db.initialSize=2
master.db.minIdle=2
master.db.maxActive=20

#slave ....
slave1.db.url=jdbc:mysql://localhost:3306/demo_db2?seUnicode=true&amp;amp;characterEncoding=UTF-8
slave1.db.username=root
slave1.db.password=123456

#slave2 ....
slave2.db.url=jdbc:mysql://localhost:3306/demo_db3?seUnicode=true&amp;amp;characterEncoding=UTF-8
slave2.db.username=root
slave2.db.password=123456

#&#x5982;&#x679C;&#x4F60;&#x8981;&#x4F7F;&#x7528;&#x5206;&#x5E93;&#x529F;&#x80FD;
#master
group1.master.db.url=jdbc:mysql://localhost:3306/demo_db?seUnicode=true&amp;amp;characterEncoding=UTF-8
group1.master.db.username=root
group1.master.db.password=123456
group1.master.db.initialSize=2
group1.master.db.minIdle=2
group1.master.db.maxActive=20

#slave ....
group1.slave1.db.url=jdbc:mysql://localhost:3306/demo_db2?seUnicode=true&amp;amp;characterEncoding=UTF-8
group1.slave1.db.username=root
group1.slave1.db.password=123456
</code></pre><p>&#x8BF4;&#x660E;</p>
<ul>
<li><code>slave</code>&#x5E8F;&#x5217;&#x4ECE;1&#x5F00;&#x59CB;,<code>group</code>&#x5E8F;&#x5217;&#x4ECE;0&#x5F00;&#x59CB;(&#x7B2C;&#x4E00;&#x7EC4;group0&#x9ED8;&#x8BA4;&#x7701;&#x7565;&#xFF0C;slave1~n,group1~n&#x4F9D;&#x6B21;&#x9012;&#x589E;) </li>
<li>&#x6BCF;&#x4E2A;&#x6570;&#x636E;&#x6E90;&#x7684;&#x914D;&#x7F6E;&#x4F1A;&#x8986;&#x76D6;&#x5168;&#x5C40;&#x914D;&#x7F6E;</li>
<li><code>db.group.size</code> &#x4E0E; <code>db.shard.size</code> &#x90FD;&#x662F;&#x5206;&#x5E93;&#x7528;&#x5230;&#x914D;&#x7F6E;&#xFF0C;&#x6CA1;&#x6709;&#x7528;&#x5230;&#x5206;&#x5E93;&#x53EF;&#x4EE5;&#x4E0D;&#x914D;&#x7F6E;</li>
</ul>
<h5 id="mybais&#x6A21;&#x5757;aop">mybais&#x6A21;&#x5757;AOP</h5>
<p>&#x5982;&#x679C;&#x4F7F;&#x7528;&#x4E86;&#x81EA;&#x52A8;cache&#x548C;&#x8BFB;&#x5199;&#x5206;&#x79BB;&#x63D2;&#x4EF6;&#xFF0C;&#x9700;&#x8981;&#x901A;&#x8FC7;AOP&#x505A;&#x7F13;&#x5B58;&#x56DE;&#x6EDA;&#xFF0C;&#x548C;&#x5F3A;&#x5236;&#x4F7F;&#x7528;master&#x751F;&#x6548;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> ${project.base.<span class="hljs-keyword">package</span>}.interceptor;

<span class="hljs-keyword">import</span> org.aspectj.lang.annotation.Aspect;
<span class="hljs-keyword">import</span> org.aspectj.lang.annotation.Pointcut;
<span class="hljs-keyword">import</span> org.springframework.core.Ordered;
<span class="hljs-keyword">import</span> org.springframework.core.annotation.Order;
<span class="hljs-keyword">import</span> org.springframework.stereotype.Component;

<span class="hljs-keyword">import</span> com.jeesuite.mybatis.spring.MybatisPluginBaseSpringInterceptor;


<span class="hljs-meta">@Aspect</span>
<span class="hljs-meta">@Component</span>
<span class="hljs-meta">@Order</span>(Ordered.HIGHEST_PRECEDENCE + <span class="hljs-number">1</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MybatisPluginSpringInterceptor</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">MybatisPluginBaseSpringInterceptor</span> </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-meta">@Pointcut</span>(<span class="hljs-string">&quot;execution(* ${project.base.package}.service.*.*(..))&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">pointcut</span><span class="hljs-params">()</span> </span>{}

}
</code></pre>
<h5 id="spring&#x914D;&#x7F6E;">spring&#x914D;&#x7F6E;</h5>
<pre><code>    &lt;!--&#x9664;&#x4E86;datasource&#x914D;&#x7F6E;&#x5916;&#xFF0C;&#x5176;&#x4ED6;&#x90FD;&#x4E0E;&#x539F;&#x751F;&#x914D;&#x7F6E;&#x4E00;&#x6837;--&gt;
    &lt;bean id=&quot;routeDataSource&quot; class=&quot;com.jeesuite.mybatis.datasource.MutiRouteDataSource&quot;&gt;
       &lt;!-- 
       &#x5982;&#x679C;&#x4F60;&#x7684;&#x6570;&#x636E;&#x5E93;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x81EA;&#x5B9A;&#x4E49;&#x4E86;&#x52A0;&#x89E3;&#x5BC6;&#x89C4;&#x5219;&#xFF0C;&#x8BF7;&#x81EA;&#x884C;&#x91CD;&#x5199;ConfigReader
       &lt;property name=&quot;configReader&quot;&gt;
           &lt;bean class=&quot;com.jeesuite.mybatis.datasource.MyConfigReader&quot; /&gt;
       &lt;/property&gt;
        --&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;transactionTemplate&quot;
        class=&quot;org.springframework.transaction.support.TransactionTemplate&quot;&gt;
        &lt;property name=&quot;transactionManager&quot; ref=&quot;transactionManager&quot; /&gt;
        &lt;property name=&quot;isolationLevelName&quot; value=&quot;ISOLATION_DEFAULT&quot; /&gt;
        &lt;property name=&quot;propagationBehaviorName&quot; value=&quot;PROPAGATION_REQUIRED&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;transactionManager&quot;
        class=&quot;org.springframework.jdbc.datasource.DataSourceTransactionManager&quot;&gt;
        &lt;property name=&quot;dataSource&quot; ref=&quot;routeDataSource&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;routeSqlSessionFactory&quot; class=&quot;org.mybatis.spring.SqlSessionFactoryBean&quot;&gt;
        &lt;property name=&quot;configLocation&quot; value=&quot;classpath:mybatis-configuration.xml&quot; /&gt;
        &lt;property name=&quot;mapperLocations&quot; value=&quot;classpath:mapper/*Mapper.xml&quot; /&gt; 
        &lt;property name=&quot;dataSource&quot; ref=&quot;routeDataSource&quot; /&gt;
        &lt;property name=&quot;typeAliasesPackage&quot; value=&quot;com.jeesuite.demo.dao.entity&quot; /&gt;
        &lt;property name=&quot;plugins&quot;&gt;
            &lt;array&gt;
                &lt;bean class=&quot;com.jeesuite.mybatis.plugin.JeesuiteMybatisInterceptor&quot;&gt;
                    &lt;property name=&quot;mapperLocations&quot; value=&quot;classpath:mapper/*Mapper.xml&quot; /&gt;
                    &lt;!--
                      &#x53EF;&#x9009;&#x503C;&#xFF1A;cache(&#x81EA;&#x52A8;&#x7F13;&#x5B58;),rwRoute(&#x8BFB;&#x5199;&#x5206;&#x79BB;),dbShard(&#x5206;&#x5E93;&#x8DEF;&#x7531;,page:&#x81EA;&#x52A8;&#x5206;&#x9875;)
                    --&gt;
                    &lt;property name=&quot;interceptorHandlers&quot; value=&quot;cache,rwRoute,page&quot; /&gt;
                    &lt;property name=&quot;properties&quot;&gt;
                        &lt;props&gt;
                            &lt;!--&#x53EF;&#x9009;&#x503C;:default(&#x9ED8;&#x8BA4;),mapper3(&#x96C6;&#x6210;mapper&#x6846;&#x67B6;)--&gt;
                            &lt;prop key=&quot;crudDriver&quot;&gt;mapper3&lt;/prop&gt;
                            &lt;prop key=&quot;dbType&quot;&gt;Mysql&lt;/prop&gt;
                            &lt;!--&#x67E5;&#x8BE2;&#x672A;&#x547D;&#x4E2D;&#x662F;&#x5426;&#x7F13;&#x5B58;&#x6807;&#x8BB0;&#xFF0C;&#x907F;&#x514D;&#x7F13;&#x5B58;&#x7A7F;&#x900F;--&gt;
                            &lt;prop key=&quot;cache.nullValue&quot;&gt;true&lt;/prop&gt;
                        &lt;/props&gt;
                    &lt;/property&gt;
                &lt;/bean&gt;
            &lt;/array&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
    &lt;!--&#x96C6;&#x6210;Mapper&#x6846;&#x67B6;&#x7684;&#x914D;&#x7F6E;,&#x6B64;&#x5904;&#x4FEE;&#x6539;&#x4E3A;tk.mybatis.spring.mapper.MapperScannerConfigurer--&gt;
    &lt;bean class=&quot;com.jeesuite.mybatis.spring.MapperScannerConfigurer&quot;&gt;
        &lt;property name=&quot;sqlSessionFactoryBeanName&quot; value=&quot;routeSqlSessionFactory&quot; /&gt;
        &lt;property name=&quot;basePackage&quot; value=&quot;com.jeesuite.demo.dao.mapper&quot; /&gt;
    &lt;/bean&gt;
</code></pre><p>&#x9ED8;&#x8BA4;&#x4F7F;&#x7528;jeesuite-cache&#x6A21;&#x5757;&#x4F5C;&#x4E3A;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x652F;&#x6301;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x9700;&#x8981;&#x4F7F;&#x7528;<code>spring-data-redis</code>&#x6216;&#x8005;&#x81EA;&#x5B9A;&#x4E49;&#xFF0C;&#x53EF;&#x4EE5;&#x6309;&#x5982;&#x4E0B;&#x914D;&#x7F6E;</p>
<pre><code>&lt;bean id=&quot;redisTemplate&quot; class=&quot;org.springframework.data.redis.core.RedisTemplate&quot;&gt;
    &lt;property name=&quot;connectionFactory&quot; ref=&quot;jedisConnectionFactory&quot; /&gt;
    ....
&lt;/bean&gt;

&lt;bean id=&quot;stringRedisTemplate&quot; class=&quot;org.springframework.data.redis.core.StringRedisTemplate&quot;&gt;
  &lt;property name=&quot;connectionFactory&quot; ref=&quot;jedisConnectionFactory&quot; /&gt;
&lt;/bean&gt;

&lt;!-- &#x4F7F;&#x7528;spring-data-redis&#x4F5C;&#x4E3A;mybatis&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x63D0;&#x4F9B;&#x8005; --&gt;
&lt;bean class=&quot;com.jeesuite.mybatis.plugin.cache.provider.SpringRedisProvider&quot;&gt;
    &lt;property name=&quot;redisTemplate&quot;  ref=&quot;redisTemplate&quot;/&gt;
    &lt;property name=&quot;stringRedisTemplate&quot; ref=&quot;stringRedisTemplate&quot; /&gt;
&lt;/bean&gt;
</code></pre><p>&#x53E6;&#x5916;&#x9700;&#x8981;&#x5728;&#x81EA;&#x5DF1;&#x9879;&#x76EE;&#x52A0;&#x5165;spring-data-redis&#x4F9D;&#x8D56;</p>
<h4 id="&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x81EA;&#x52A8;&#x7F13;&#x5B58;">&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x81EA;&#x52A8;&#x7F13;&#x5B58;</h4>
<p>&#x53EA;&#x9700;&#x8981;&#x5728;mapper&#x63A5;&#x53E3;&#x589E;&#x52A0;<strong>@com.jeesuite.mybatis.plugin.cache.annotation.Cache</strong>&#x6807;&#x6CE8;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">UserEntityMapper</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">BaseMapper</span>&lt;<span class="hljs-title">UserEntity</span>&gt; </span>{

    <span class="hljs-meta">@Cache</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> UserEntity <span class="hljs-title">findByMobile</span><span class="hljs-params">(@Param(<span class="hljs-string">&quot;mobile&quot;</span>)</span> String mobile)</span>;

    <span class="hljs-meta">@Cache</span>
    <span class="hljs-function">List&lt;String&gt; <span class="hljs-title">findByType</span><span class="hljs-params">(@Param(<span class="hljs-string">&quot;type&quot;</span>)</span> <span class="hljs-keyword">int</span> type)</span>;
}
</code></pre>
<p>&#x914D;&#x7F6E;&#x5B8C;&#x6210;&#x5373;&#x53EF;&#xFF0C;&#x67E5;&#x8BE2;&#x4F1A;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x3001;&#x66F4;&#x65B0;&#x4F1A;&#x81EA;&#x52A8;&#x66F4;&#x65B0;&#x3002;</p>
<h4 id="&#x4E00;&#x4E9B;&#x5176;&#x4ED6;&#x8BF4;&#x660E;">&#x4E00;&#x4E9B;&#x5176;&#x4ED6;&#x8BF4;&#x660E;</h4>
<h5 id="&#x5F00;&#x542F;&#x4E86;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x6570;&#x636E;&#x5E93;&#x4E8B;&#x52A1;&#x5931;&#x8D25;&#x5199;&#x5165;&#x7F13;&#x5B58;&#x5982;&#x4F55;&#x5904;&#x7406;&#xFF1F;">&#x5F00;&#x542F;&#x4E86;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x6570;&#x636E;&#x5E93;&#x4E8B;&#x52A1;&#x5931;&#x8D25;&#x5199;&#x5165;&#x7F13;&#x5B58;&#x5982;&#x4F55;&#x5904;&#x7406;&#xFF1F;</h5>
<ul>
<li>&#x5728;&#x4E8B;&#x52A1;&#x5931;&#x8D25;&#x540E;&#x8C03;&#x7528;<strong>CacheHandler.rollbackCache(),</strong>&#x901A;&#x5E38;&#x5728;&#x4E1A;&#x52A1;&#x7684;&#x62E6;&#x622A;&#x5668;&#x7EDF;&#x4E00;&#x5904;&#x7406;<h5 id="&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x7684;&#x5B9E;&#x4F53;&#x5982;&#x4F55;&#x66F4;&#x65B0;&#xFF1F;">&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x7684;&#x5B9E;&#x4F53;&#x5982;&#x4F55;&#x66F4;&#x65B0;&#xFF1F;</h5>
</li>
<li>&#x9996;&#x5148;&#x67E5;&#x8BE2;&#x51FA;&#x5B9E;&#x4F53;&#x5BF9;&#x8C61;&#xFF0C;UserEntity entity = mapper.get...(id);</li>
<li>&#x7136;&#x540E;&#x901A;&#x8FC7;mapper.updateSelective(entity);</li>
</ul>
<p>&#x5982;&#x679C;&#x4E0D;&#x5168;&#x91CF;&#x66F4;&#x65B0;&#x4F1A;&#x5BFC;&#x81F4;&#x7F13;&#x5B58;&#x7684;&#x5185;&#x5BB9;&#x662F;&#x6709;&#x90E8;&#x5206;&#x5B57;&#x6BB5;&#xFF0C;&#x56E0;&#x4E3A;update&#x540E;&#x4F1A;&#x90A3;&#x6700;&#x65B0;&#x7684;entity&#x66F4;&#x65B0;&#x7F13;&#x5B58;&#x3002;</p>
<h5 id="&#x5982;&#x679C;&#x624B;&#x52A8;&#x66F4;&#x65B0;&#x6216;&#x5199;&#x5165;&#x5B9E;&#x4F53;&#x7F13;&#x5B58;&#xFF1F;">&#x5982;&#x679C;&#x624B;&#x52A8;&#x66F4;&#x65B0;&#x6216;&#x5199;&#x5165;&#x5B9E;&#x4F53;&#x7F13;&#x5B58;&#xFF1F;</h5>
<p>&#x63D0;&#x4F9B;EntityCacheHelper&#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x624B;&#x52A8;&#x5199;&#x5165;&#x7F13;&#x5B58;&#x4E5F;&#x5C06;&#x7EB3;&#x5165;&#x81EA;&#x52A8;&#x7F13;&#x5B58;&#x7BA1;&#x7406;&#xFF0C;&#x65E0;&#x9700;&#x62C5;&#x5FC3;&#x7F13;&#x5B58;&#x66F4;&#x65B0;&#x95EE;&#x9898;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-comment">/**
     * &#x67E5;&#x8BE2;&#x5E76;&#x7F13;&#x5B58;&#x7ED3;&#x679C;
     * <span class="hljs-doctag">@param</span> entityClass &#x5B9E;&#x4F53;&#x7C7B;class (&#x7528;&#x6237;&#x7EC4;&#x88C5;&#x5B9E;&#x9645;&#x7684;&#x7F13;&#x5B58;key)
     * <span class="hljs-doctag">@param</span> key &#x7F13;&#x5B58;&#x7684;key&#xFF08;&#x548C;entityClass&#x4E00;&#x8D77;&#x7EC4;&#x6210;&#x771F;&#x5B9E;&#x7684;&#x7F13;&#x5B58;key&#x3002;&lt;br&gt;&#x5982;entityClass=UserEntity.class,key=findlist&#xFF0C;&#x5B9E;&#x9645;&#x7684;key&#x4E3A;&#xFF1A;UserEntity.findlist&#xFF09;
     * <span class="hljs-doctag">@param</span> expireSeconds &#x8FC7;&#x671F;&#x65F6;&#x95F4;&#xFF0C;&#x5355;&#x4F4D;&#xFF1A;&#x79D2;
     * <span class="hljs-doctag">@param</span> dataCaller &#x7F13;&#x5B58;&#x4E0D;&#x5B58;&#x5728;&#x6570;&#x636E;&#x52A0;&#x8F7D;&#x6E90;
     * <span class="hljs-doctag">@return</span>
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> &lt;T&gt; <span class="hljs-function">T <span class="hljs-title">queryTryCache</span><span class="hljs-params">(Class&lt;? extends BaseEntity&gt; entityClass,String key,<span class="hljs-keyword">long</span> expireSeconds,Callable&lt;T&gt; dataCaller)</span>
</span></code></pre>
<pre><code class="lang-java"><span class="hljs-comment">//&#x751F;&#x6210;&#x7684;&#x7F13;&#x5B58;key&#x4E3A;&#xFF1A;UserEntity.findByStatus:2</span>
EntityCacheHelper.queryTryCache(UserEntity.class, <span class="hljs-string">&quot;findByStatus:2&quot;</span>, <span class="hljs-keyword">new</span> Callable&lt;List&lt;UserEntity&gt;&gt;() {
    <span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;UserEntity&gt; <span class="hljs-title">call</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> Exception </span>{
      <span class="hljs-comment">//&#x67E5;&#x8BE2;&#x8BED;&#x53E5;</span>
      List&lt;UserEntity&gt; entitys = mapper.findByStatus((<span class="hljs-keyword">short</span>)<span class="hljs-number">2</span>);
      <span class="hljs-keyword">return</span> entitys;
   }
});
</code></pre>
<h4 id="&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x5206;&#x9875;">&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x5206;&#x9875;</h4>
<h5 id="1&#x6807;&#x6CE8;&#x65B9;&#x5F0F;pageable">1.&#x6807;&#x6CE8;&#x65B9;&#x5F0F;(<code>@Pageable</code>)</h5>
<pre><code class="lang-java"><span class="hljs-comment">//mapper&#x63A5;&#x53E3;</span>
<span class="hljs-meta">@Pageable</span>
<span class="hljs-function">List&lt;UserEntity&gt; <span class="hljs-title">findByStatus</span><span class="hljs-params">(<span class="hljs-keyword">short</span> status)</span></span>;

<span class="hljs-comment">//&#x8C03;&#x7528;</span>
Page&lt;UserEntity&gt; pageInfo = mapper.pageQuery(<span class="hljs-keyword">new</span> PageParams(<span class="hljs-number">1</span>,<span class="hljs-number">5</span>));
</code></pre>
<h5 id="2page&#x65B9;&#x6CD5;&#x5B9A;&#x4E49;&#x65B9;&#x5F0F;">2.page&#x65B9;&#x6CD5;&#x5B9A;&#x4E49;&#x65B9;&#x5F0F;</h5>
<pre><code class="lang-java"><span class="hljs-comment">//mapper&#x63A5;&#x53E3;</span>
<span class="hljs-meta">@Select</span>(<span class="hljs-string">&quot;SELECT * FROM users where 1=1&quot;</span>)
<span class="hljs-function">Page&lt;UserEntity&gt; <span class="hljs-title">pageQuery</span><span class="hljs-params">(@Param(<span class="hljs-string">&quot;pageParam&quot;</span>)</span> PageParams pageParam)</span>;

<span class="hljs-comment">//&#x8C03;&#x7528;</span>
Page&lt;UserEntity&gt; pageInfo = PageExecutor.pagination(<span class="hljs-keyword">new</span> PageParams(<span class="hljs-number">1</span>,<span class="hljs-number">10</span>), <span class="hljs-keyword">new</span> PageDataLoader&lt;UserEntity&gt;() {
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;UserEntity&gt; <span class="hljs-title">load</span><span class="hljs-params">()</span> </span>{
       <span class="hljs-keyword">return</span> mapper.findByStatus((<span class="hljs-keyword">short</span>)<span class="hljs-number">1</span>);
    }
});
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="spring.html" class="navigation navigation-prev " aria-label="Previous page: Spring模块">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="cache.html" class="navigation navigation-next " aria-label="Next page: cache模块">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"mybatis模块","level":"1.3.4","depth":2,"next":{"title":"cache模块","level":"1.3.5","depth":2,"path":"jeesuite-libs/cache.md","ref":"jeesuite-libs/cache.md","articles":[]},"previous":{"title":"Spring模块","level":"1.3.3","depth":2,"path":"jeesuite-libs/spring.md","ref":"jeesuite-libs/spring.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"jeesuite-libs/mybatis.md","mtime":"2018-05-04T10:24:19.071Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-05-04T10:30:11.187Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

